package part17;

import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.concurrent.*;

/**
 * @author wcj
 * @Date 2021/6/1 18:48
 * @Version 1.0
 */
public class Part1710 {

    private static int count = 10;

    static <T> void test(Queue<T> queue, Generator<T> gen) {
        for (int i = 0; i < count; i++) {
            queue.offer(gen.next());
        }
        while (queue.peek() != null) {
            System.out.print(queue.remove() + " ");
        }
        System.out.println();
    }

    static class Gen implements Generator<String> {
        String[] s = "one two three four five six seven eight nine ten".split(" ");
        private int i;

        @Override
        public String next() {
            return s[i++];
        }
    }

    /**
     * 队列的类别:一般的LinkedList,PriorityQueue,
     * 有界队列：ArrayBlockingQueue,LinkedBlockingQueue,PriorityBlockingQueue
     * 用于并发的队列:ConcurrentLinkedQueue
     * 一般队列，优先级队列是因为实现了Comparable接口，双端队列
     *
     * @param args
     */
    public static void main(String[] args) {
        test(new LinkedList<String>(), new Gen());
        test(new PriorityQueue<String>(), new Gen());
        test(new ArrayBlockingQueue<String>(count), new Gen());
        test(new ConcurrentLinkedQueue<String>(), new Gen());
        test(new LinkedBlockingQueue<String>(), new Gen());
        test(new PriorityBlockingQueue<String>(), new Gen());

    }
}
